package com.bjx.system.controller;

import cn.hutool.core.lang.tree.Tree;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.system.domain.vo.MenuVO;
import com.bjx.system.service.IMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 菜单控制器
 * @author: liushuai
 * @date: 2022/7/6 13:50
 */
@RestController
@Tag(name = "菜单控制器")
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    /**
     * 查询所有菜单权限列表树
     * @return: R<IPage<MenuVO>>
     * @Author: liushuai
     * @Date: 2022/10/12
     */
    @Operation(summary = "查询所有菜单权限列表树")
    @GetMapping("listMenuAuthTree")
    public R<List<Tree<String>>> listMenuAuthTree() {
        List<Tree<String>> menuTree = menuService.listMenuAuthTree();
        return R.success(menuTree);
    }

    /**
     * 新增菜单
     * @param menuVO
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/7/7 14:43
     */
    @Operation(summary = "新增菜单")
    @PostMapping("/insertMenu")
    public R insertMenu(@RequestBody @Validated MenuVO menuVO){
        menuService.insertMenu(menuVO);
        return R.successMsg("保存成功");
    }

    /**
     * 查询菜单树
     * @param
     * @return: com.bjx.common.core.domain.R<cn.hutool.core.lang.tree.Tree<java.lang.String>>
     * @Author: liushuai
     * @Date: 2022/7/7 15:24
     */
    @Operation(summary = "查询菜单树")
    @GetMapping("/listMenuTreeByLoginUser")
    public R<List<Tree<String>>>  listMenuTreeByLoginUser(){
        List<Tree<String>> menuTree = menuService.listMenuTreeByLoginUser();
        return R.success(menuTree);
    }




    /**
     * 根据菜单id查询菜单
     * @param menuId
     * @return:R<MenuVO>
     * @Author: liushuai
     * @Date: 2022/10/12
     */
    @Operation(summary = "根据菜单id查询菜单")
    @GetMapping("selectMenuByMenuId")
    public R<MenuVO> selectMenuByMenuId(@RequestParam Long menuId){
        MenuVO vo = menuService.selectMenuByMenuId(menuId);
        return R.success(vo);
    }

    /**
     * 根据菜单id删除菜单
     * @param menuId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/12
     */
    @Operation(summary = "根据菜单id删除菜单")
    @GetMapping("deleteMenuByMenuId")
    public R deleteMenuByMenuId(@RequestParam Long menuId){
        menuService.deleteMenuByMenuId(menuId);
        return R.successMsg("删除菜单成功");
    }



    /**
     * 修改菜单
     * @param menuVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/12
     */
    @Operation(summary = "修改菜单")
    @PostMapping("updateMenu")
    public R updateMenu(@RequestBody @Validated(Update.class) MenuVO menuVO){
        menuService.updateMenu(menuVO);
        return R.successMsg("修改菜单成功");
    }

}
